/*
 * label_list.c
 *
 *  Created on: 07/10/2013
 *      Author: vitor
 */
#include "string_int_list.h"

void init(stringIntList** stringIntListAddress) {
	stringIntListAddress = NULL;
}

void addStringInt(stringIntList** stringIntListAddress, stringInt toAdd) {
	stringIntList* aux;
	stringIntList* aux2;

	aux = malloc(sizeof(stringIntList));
	aux->stringInt = toAdd;
	aux->nextElement = NULL;

	if (*stringIntListAddress == NULL ) {
		*stringIntListAddress = aux;
	} else {
		aux2 = *stringIntListAddress;

		while (aux2->nextElement != NULL ) {
			aux2 = aux2->nextElement;
		}

		aux2->nextElement = aux;
	}
}

int searchByString(stringIntList* toSearch, char* name, stringInt* result) {
	stringIntList* aux;

	aux = toSearch;

	while (aux != NULL ) {
		if (strcasecmp(aux->stringInt.string, name) == 0) {
			*result = aux->stringInt;
			return 1;
		}
		aux = aux->nextElement;
	}

	return 0;
}

void printContents(stringIntList* toPrint) {
	stringIntList* aux;

	aux = toPrint;

	while (aux != NULL ) {
		printf("%s %x\n", aux->stringInt.string, aux->stringInt.intValue);
		aux = aux->nextElement;
	}
}
